package cn.ybk.order.service.impl;

import cn.ybk.basic.util.CodeGenerateUtils;
import cn.ybk.order.domain.OrderPetAcquisition;
import cn.ybk.order.domain.OrderProduct;
import cn.ybk.order.dto.ConfirmDto;
import cn.ybk.order.mapper.OrderProductMapper;
import cn.ybk.order.service.IOrderProductService;
import cn.ybk.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.lang.model.type.DeclaredType;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 11
 * @since 2023-03-18
 */
@Service
public class OrderProductServiceImpl extends BaseServiceImpl<OrderProduct> implements IOrderProductService {

    @Autowired
    private OrderProductMapper orderProductMapper;

    // 订单确认
    @Override
    public void confirm(ConfirmDto dto) {
        // 修改状态为已支付
        OrderProduct order = orderProductMapper.findById(dto.getId());
        order.setPrice(dto.getMoney());
        order.setOrderSn(CodeGenerateUtils.generateOrderSn(dto.getId()));
        order.setLastPayTime(new Date(System.currentTimeMillis()));
        order.setState(1);
        orderProductMapper.update(order);
    }


    // 订单取消
    @Override
    public void cancel(Long id) {
        orderProductMapper.delete(id);
    }

}
